package com.yx.cloud;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.multidex.MultiDex;

import com.iot.common.utils.LogUtils;
import com.iot.sdk.yugong.YuGongSdk;
import com.iot.sdk.yugong.YuGongSdkConfig;
import com.iot.sweeper.AppContext;
import com.tencent.bugly.crashreport.CrashReport;
import com.yx.cloud.product.ProductManager;
import com.yx.cloud.receiver.GlobalBroadcastReceiver;

import java.util.Locale;

/**
 * Created by Administrator on 2018/12/26.
 */

public class MyApplication extends Application implements Application.ActivityLifecycleCallbacks {

    private static Context mContext;
    public static GlobalBroadcastReceiver receiver;
    public static boolean recvActive = false;//是否当前接收广播消息

    public static Context get() {
        return mContext;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
        //bugly 初始化
        // com.aliyun.alink.linksdk.tools.ALog.setLevel((byte) (0));//阿里日志
        //        AliGenieSdk.init();
        //CrashReport.initCrashReport(getApplicationContext(), "662e0372d3", false);//华为上架检测到了 让说明 徐老师让去掉

        String language = Locale.getDefault().getLanguage();
        String countryCode = Locale.getDefault().getCountry();
        int countryNumber = 86;
        if ("CN".equalsIgnoreCase(countryCode)) {
            countryNumber = 86;
        }
        registerActivityLifecycleCallbacks(this);
        YuGongSdkConfig config = YuGongSdkConfig.newBuilder(this)
                .appId("SilverStar")
                .appVersion(BuildConfig.VERSION_NAME)
                .clientId("yugong_app")
                .countryCode(countryNumber + "")
                .language(language)
                .type(YuGongSdk.class)
                .extra("adfa ").build();
        AppContext.init(config);
        //注册产品
        ProductManager.init();

    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }

    @Override
    public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) {
        LogUtils.i("ActivityLifecycle: " + activity.getLocalClassName());
    }

    @Override
    public void onActivityStarted(@NonNull Activity activity) {
        LogUtils.i("ActivityLifecycle: " + activity.getLocalClassName());
    }

    @Override
    public void onActivityResumed(@NonNull Activity activity) {
        LogUtils.i("ActivityLifecycle: " + activity.getLocalClassName());
    }

    @Override
    public void onActivityPaused(@NonNull Activity activity) {
        LogUtils.i("ActivityLifecycle: " + activity.getLocalClassName());
    }

    @Override
    public void onActivityStopped(@NonNull Activity activity) {
        LogUtils.i("ActivityLifecycle: " + activity.getLocalClassName());
    }

    @Override
    public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {
        LogUtils.i("ActivityLifecycle: " + activity.getLocalClassName());
    }

    @Override
    public void onActivityDestroyed(@NonNull Activity activity) {
        LogUtils.i("ActivityLifecycle: " + activity.getLocalClassName());
    }

}
